package com.example.administrator.yuejian23.Fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian23.Bean.AskList;
import com.example.administrator.yuejian23.Model;
import com.example.administrator.yuejian23.R;
import com.example.administrator.yuejian23.Const;
import com.example.administrator.yuejian23.adapter.MonAdapter;
import com.example.administrator.yuejian23.Retrofit.RetrofitService             ;
import com.example.administrator.yuejian23.Bean.MonList;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * A simple {@link Fragment} subclass.
 */
public class MonsterFragment extends Fragment {
    private List<MonList> list;
    private Context context;
    private MonAdapter adapter;
    private View view;
    private Retrofit retrofit;
    private RecyclerView recyclerView;
    public MonsterFragment() {
        // Required empty public constructor
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view=inflater.inflate(R.layout.fragment_monster, container, false);
        init();
        event();
        return view;
    }
    public void init()
    {
        recyclerView=(RecyclerView)view.findViewById(R.id.L_teacher);
        context=getActivity();
    }
    public void event()
    {
        retrofit = new Retrofit.Builder().
                baseUrl(Const.BASE_URL).
                addConverterFactory(GsonConverterFactory.create()).
                build();
        RetrofitService retrofitService = retrofit.create(RetrofitService.class);
        Call<List<MonList>> call=retrofitService.getMonList(1);
        call.enqueue(new Callback<List<MonList>>() {
            @Override
            public void onResponse(Call<List<MonList>> call, Response<List<MonList>> response) {
                list=response.body();
                adapter=new MonAdapter(context,list);
                LinearLayoutManager manager=new LinearLayoutManager(context);
                manager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setAdapter(adapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
                recyclerView.setLayoutManager(manager);
            }

            @Override
            public void onFailure(Call<List<MonList>> call, Throwable t) {

            }
        });
    }
}


